/**
 * @Title: 预约指令下发类
 * @author pengyu
 * @date 2015年12月15日 上午10:21:55
 * @version V1.0
 */
package tt.dz.mvc.controller.middleware;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.alibaba.fastjson.JSON;

import tt.dz.entity.base.JsonCommon;
import tt.dz.entity.base.JsonForHardware;
import tt.dz.entity.base.JsonForList;
import tt.dz.mvc.controller.base.BaseController;
import tt.dz.service.middleware.OmsBespeakService;
import tt.dz.util.OmsConstant;
import tt.dz.util.StringUtil;

@Controller
public class BespeakFormThirdController extends BaseController
{
	/**
	 * 日志对象
	 */
	private Logger logger = LoggerFactory.getLogger(BespeakFormThirdController.class);
	@Autowired
	OmsBespeakService omsBespeakService;
	//  3.1.4. 开始预约    AS 调用OMS，OMS请求中间件  api_v3.php中的bespeakDianzhuang方法
	//AS 请求 OMS ，OMS 下发充电 socket，只下发，短连接  
	//	2.1版本需要发送预约费用 ,单独 一个接口   是哪边生成预约流水号。   什么时候AS传达费用信息给oms
	//操作流水号	bespeak_jrnl	操作流水号:如果2.0中AS生成发给OMS，就存在OMS中；如果不存，则OMS自动根据时间\电桩地址和其他规则生成；此字段用来关联充电费用记录。0000000000为非真实数据。		varchar(50)	50		FALSE	TRUE	FALSE
	@RequestMapping("/thirdBespeak") 
	public JsonCommon<String> bespeak(HttpServletRequest request, HttpServletResponse response) throws Exception {
		Map<String,String> map = StringUtil.getParameterByOms(request);
//		String portNo = request.getParameter("portNo");//AS传值
//		String chargerId = request.getParameter("chargerId");//AS传值
//		String userCard = request.getParameter("userCard");//AS传值
//		String bespeakMinute = request.getParameter("bespeakMinute");//AS传值  预约时长
//		return omsBespeakService.bespeak(chargerId,portNo,userCard,bespeakMinute);
		return omsBespeakService.bespeak(map);
//		return "sendSocket success";
	}	
	
	//AS 请求 OMS ，OMS 下发预约返回  后:中间件回复http，OMS同步返回报文头     api_v3.php中的  controlBespeakReturn($thisDate,"1");
	@RequestMapping("/thirdBespeakReturn") 
	public JsonCommon<String> bespeakReturn(HttpServletRequest request, HttpServletResponse response) throws Exception {
		Map<String,String> map = StringUtil.getParameterByMiddle(request);
		omsBespeakService.bespeakReturn(map);
		return new JsonCommon(OmsConstant.SuccessCodeEnum.SuccessCode.value(), OmsConstant.SuccessCodeEnum.SuccessCode.desc());
	}	
	
	//3.1.5. 结束预约     AS 请求 OMS ，OMS 下发充电 socket，只下发，短连接  startChargeReturn   api_v3.php中的  cancelBespeakDianzhuang 
	@RequestMapping("/thirdCancelBespeak") 
	public JsonCommon<String> cancelBespeak(HttpServletRequest request, HttpServletResponse response) throws Exception {
		Map<String,String> map = StringUtil.getParameterByMiddle(request);
//		String chargerId = request.getParameter("chargerId");//AS传值
//		String portNo = request.getParameter("portNo");//AS传值
//		String userCard = request.getParameter("userCard");//AS传值
//		return omsBespeakService.cancelBespeak(chargerId,portNo,userCard);
		return omsBespeakService.cancelBespeak(map);
	}		
	//AS 请求 OMS ，OMS 下发取消预约 后:中间件回复http，同步返回报文头  controlBespeakReturn
	@RequestMapping("/thirdCancelBespeakReturn") 
	public JsonCommon<String> cancelBespeakReturn(HttpServletRequest request, HttpServletResponse response) throws Exception {
		Map<String,String> map = StringUtil.getParameterByMiddle(request);
		omsBespeakService.cancelBespeakReturn(map);
		return new JsonCommon(OmsConstant.SuccessCodeEnum.SuccessCode.value(), OmsConstant.SuccessCodeEnum.SuccessCode.desc());
	}			
	
	
}
